package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.merchant.domain.CityInfo;
import com.ruoyi.merchant.domain.DistrictInfo;
import com.ruoyi.merchant.domain.ProvinceInfo;
import com.ruoyi.merchant.service.CityInfoService;
import com.ruoyi.merchant.service.DistrictInfoService;
import com.ruoyi.merchant.service.ProinceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 省市区选择
 */
@RestController
@RequestMapping("/region")
public class RegionInfoController {

    @Autowired
    private ProinceInfoService proinceInfoService;

    @Autowired
    private CityInfoService cityInfoServicel;

    @Autowired
    private DistrictInfoService districtInfoService;

    @GetMapping("/province/list")
    public AjaxResult listProvince() {
        List<ProvinceInfo> list = proinceInfoService.list();
        return AjaxResult.success(list);
    }

    @GetMapping("/city/listByProvinceId")
    public AjaxResult listCityInfoByProvinceId(@RequestParam Integer provinceId) {
        List<CityInfo> list = cityInfoServicel.list(provinceId);
        return AjaxResult.success(list);
    }

    @GetMapping("/district/listByCityId")
    public AjaxResult listDistrictInfoByCityId(@RequestParam Integer cityId) {
        List<DistrictInfo> list = districtInfoService.list(cityId);
        return AjaxResult.success(list);
    }

}
